package com.jsq;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }

    private void init() {
        // 数字0按钮
        Button btn_num0 = (Button) findViewById(R.id.btn_num0);
        // 数字1按钮
        Button btn_num1 = (Button) findViewById(R.id.btn_num1);
        // 数字2按钮
        Button btn_num2 = (Button) findViewById(R.id.btn_num2);
        // 数字3按钮
        Button btn_num3 = (Button) findViewById(R.id.btn_num3);
        // 数字4按钮
        Button btn_num4 = (Button) findViewById(R.id.btn_num4);
        // 数字5按钮
        Button btn_num5 = (Button) findViewById(R.id.btn_num5);
        // 数字6按钮
        Button btn_num6 = (Button) findViewById(R.id.btn_num6);
        // 数字7按钮
        Button btn_num7 = (Button) findViewById(R.id.btn_num7);
        // 数字8按钮
        Button btn_num8 = (Button) findViewById(R.id.btn_num8);
        // 数字9按钮
        Button btn_num9 = (Button) findViewById(R.id.btn_num9);
        // 加号按钮
        Button btn_plus = (Button) findViewById(R.id.btn_plus);
        // 减号按钮
        Button btn_minus = (Button) findViewById(R.id.btn_minus);
        // 乘号按钮
        Button btn_multiply = (Button) findViewById(R.id.multiply);
        // 除号按钮
        Button btn_divide = (Button) findViewById(R.id.btn_divide);
        // 等号按钮
        Button btn_equal = (Button) findViewById(R.id.btn_equal);
        // 小数点按钮
        Button btn_point = (Button) findViewById(R.id.btn_point);
        // 清除按钮
        Button btn_clear = (Button) findViewById(R.id.btn_clear);
        // 删除按钮
        Button btn_delete = (Button) findViewById(R.id.btn_delete);

        btn_num0.setOnClickListener(this);
        btn_num1.setOnClickListener(this);
        btn_num2.setOnClickListener(this);
        btn_num3.setOnClickListener(this);
        btn_num4.setOnClickListener(this);
        btn_num5.setOnClickListener(this);
        btn_num6.setOnClickListener(this);
        btn_num7.setOnClickListener(this);
        btn_num8.setOnClickListener(this);
        btn_num9.setOnClickListener(this);
        btn_plus.setOnClickListener(this);
        btn_minus.setOnClickListener(this);
        btn_multiply.setOnClickListener(this);
        btn_divide.setOnClickListener(this);
        btn_equal.setOnClickListener(this);
        btn_point.setOnClickListener(this);
        btn_clear.setOnClickListener(this);
        btn_delete.setOnClickListener(this);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View view) {
        Button btn = (Button) view;
        Log.i(TAG, btn.getText().toString());
    }
}
